Brief introductionPython-nmap is a Python library that uses nmap for port scanning, which makes it easy to generate NMAP scan reports and can help system administrators automate scan tasks and generate reports. At the same time, it also supports Nmap script output.You can see that Python-nmap has only four py files (__init__.py, nmap.py, test.py, test_nmap.py), Here's a read.__init__.pyExcept for dozens of lines of comments, the real code is only four lines, the basic content is to import some b
RST package, the port is closed, and if you receive a syn/ack packet, the corresponding port is open.
TCP FIN Scan: This way sends a FIN packet that represents the removal of an active TCP connection and lets the other person close the connection. If an RST package is received, the corresponding port is closed.
TCP Xmas Scan: This method is set to 1 packets by sending the PSH, FIN, URG, and TCP flag bits. If an RST package is received, the corresponding port is closed.
Below we will use Python3
active TCP connection and lets the other person close the connection. If an RST package is received, the corresponding port is closed.
TCP Xmas Scan: This method is set to 1 packets by sending the PSH, FIN, URG, and TCP flag bits. If an RST package is received, the corresponding port is closed.
Below we will use Python3 to implement the TCP full-port scanner, the following into the programming link.Coding combat全连接扫描The core of the approach is to make a TCP connection for different por
/bin/python3# -*- coding: utf-8 -*-from socket import *def portScanner(host,port): try: s = socket(AF_INET,SOCK_STREAM) s.connect((host,port)) print('[+] %d open' % port) s.close() except: print('[-] %d close' % port)def main(): setdefaulttimeout(1) for p in range(1,1024): portScanner('192.168.0.100',p)if name == 'main': main()
The core of this code isportScannerFunction. it can be se
to remove an active TCP connection is sent to the other party to close the connection. If an RST packet is received, the corresponding port is closed.
Tcp xmas scan: This method sends packets with PSH, FIN, URG, and TCP flag set to 1. If an RST packet is received, the corresponding port is closed.
Next we will use Python3 to implement a TCP full-connection port scanner. Next we will go to the programming stage.
Coding practices
Full connection ScanThe core method is to establish TCP connections
1 #Coding=utf-82 3 ImportNmap4 ImportOptparse5 ImportThreading6 ImportSYS7 ImportRe8 " "9 need to install PYTHON_NMAP package, support 2.x and 3.xTen The Python_nmap package provides a series of interfaces that Python calls Nmap One A (i) Important categories and methods: - 1. Create an NMAP scanner - class Portscanner () the __init__ (Self, nmap_search_path= (' Nmap ', '/usr/bin/nmap ', '/usr/local/bin/nmap ', '/sw/bin/nmap ', '/opt/local/ Bin/nmap
Python's third-party module, PYTHON-NMAP for efficient port scanning.First, the preparatory workYum-y Install nmap #安装nmap工具pip install python-nmap==0.4.0 #python2.7 Environment using PIP installation 0.4.0 version of the third-party moduleIi. description of common methods of modulesHere we mainly accept the Python-nmap module of the two common classes, one is the Portscanner () class, implementation of a NMAP tool port scanning function encapsulation
1) Description of the problemThe following exception is thrown under Windows.Traceback (most recent): File"ftplogin_file.py", line 111,inchMain () File"ftplogin_file.py", line 109,inchmain FTPLogin (filepath) File"ftplogin_file.py", Line 77,inchFTPLoginifNmapscan (IP," +") ==True:file"ftplogin_file.py", line 8,inchNmapscan Nmscan=Nmap. Portscanner () File"C:\Python27\lib\site-packages\nmap\nmap.py", line 144,inch __init__ RaisePortscannererror ('
IntroducedPython-nmap is a port scanning tool based on the system Nmap command, which is simple and convenient to use.Recently, in order to enhance server security and supervision, it is necessary to keep the company server open port scan records every day, once there is an increase in the decrease can be found.Previously wrote a https://github.com/bashhu/monitor-shell/blob/master/python-script/scan_port.sh with the shell.Recently, we are going to improve our operation and maintenance platform,
Python_clamad implement efficient Port scanner Pythonnmappython third-party module PYTHONNMAP for efficient port scanning the installation method of the Python-nmap module is as follows: Yum-yinstall nmap #安装nmap工具pip installpython-nmap# Module Source installation ##https://pypi.python.org/pypi/ python-nmaptar-zxvfpython-nmap-0.1.4.tar.gzcdpython-nmap-0.1.4pythonsetup.py Installlinux under the Security Scanning Tool Nmap usage detailed http://www.aiezu.com/system/linux/linux_nmap_tutorial.html4.
Installing the Nmap module:Pip Install Python_nmaNmap Module Description:Python-nmap is a Python library that helps to use the Nmap port scanner. It allows easy manipulation of NMAP scan results and will be a perfect choice for tools and reports from system administrators who need to automate the scanning task. It also supports Nmap script output.Nmap Module class:Et:python's lightweight XML supportPortscanner: Port ScanPortscannerasync: Port scan is asynchronousPortscannererror:nmap Class of Ex
and does not send any messages to the target host:
NMAP-SL 192.168.1.0/24
To probe open ports on the target host, you can specify a comma-delimited list of ports (such as-ps22,23,25,80):
Nmap-ps 192.168.1.234
To probe a host using UDP ping:
Nmap-pu 192.168.1.0/24
The most Frequently used scan option: A SYN Scan, also known as a semi-open scan, does not open a full TCP connection and executes quickly:
Nmap-ss 192.168.1.0/24
Nmap Installation
This article takes Linux Ubuntu16.04 as an example, a
socket and connects it to the specified port number for the specified IP address.Public Socket (inetaddress address,int port,inetaddress localaddr,int localport) throws IOException creates a socket and connects it to the specified remote port on the specified remote address. The socket binds the provided local address and port by calling the bind () function.In addition to the first, the other 4 construction methods attempt to establish a connection to the server, and if the connection succeeds
First edition: Only comma-separated ports are supported and port ranges are not supported
Firstly:sudo Apt-get Install Nmap
Secondly:pip Install Python-nmap
Thirdly:copy the code bellow to a file like scan_network.py
#!/usr/bin/env pythonimport nmapimport optparsedef nmapScan (TgtHost, Tgtport): Nmscan = Nmap. Portscanner () Nmscan.scan (tgthost,tgtport) state=nmscan[tgthost][' TCP '][int (tgtport) [' State '] print ("[*]" + TG Thost + "tcp/" +tgtpo
I. Description of the toolCall Nmap library for port scanningSecond, demonstrate the use of the effect650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/8C/31/wKiom1hkumqAIUmwAASq5uUuz9s324.png "title=" Nmapscan.png "alt=" Wkiom1hkumqaiumwaasq5uuuz9s324.png "/>Third, Code + CommentsImportnmapimportargparsedefnmapscan (Host,port):# Call Nmap's Portscanner class nm=nmap. Portscanner () # scan results=
ImportNmap#Import nmap.py ModuleNM = Nmap. Portscanner ()#instantiation of Nmap. Portscanner ObjectNm.scan ('127.0.0.1','22-443')#Scan 127.0.0.1, port number from 22 to 443Nm.command_line ()#gets the command line that currently performs the scan: Nmap-ox-P 22-443 127.0.0.1Nm.scaninfo ()#get Nmap Scan information {' TCP ': {' services ': ' 22-443 ', ' method ': ' Connect '}}Nm.all_hosts ()#get all the hosts
,whitelist): p=re.compile ("^ (\d*) \-(\d*) $ ") Iftype (hostlist) !=list: help () portmatch=re.match (p, Portrange) ifnotportmatch: Help () l=[] forhostinhostlist: result= ' nm=nmap. Portscanner () NBSP;NBSP;NBSP;NBSP;NBSP;NBSP;NBSP;NBSP;NBSP;NBsp;tmp=nm.scan (Host,portrange) result=result+ "mutinmscan.py port scan of the multi-process version, compared to single-threaded version of the largest one change is the implementation of the Nmscan function
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.